package com.yuekao.servlet;


import com.yuekao.mycrawlertest.db.mapper.SchoolMapper;
import com.yuekao.mycrawlertest.db.vo.School;
import com.yuekao.mycrawlertest.db.vo.pageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * 登录获取
 */
@Controller
public class Index {

    @Autowired
    private SchoolMapper schoolMapper;
    @RequestMapping("/index")
    public String ftlIndex(HttpServletRequest request) {
        //获取全部文件个数
        int totalNum = schoolMapper.getToTalNum();
        //页数
        int pageNum = totalNum/15;
        if ((totalNum%15)!=0){
            pageNum++;
        }
        List<pageBean> numbers = new ArrayList<>();
        for(int i = 1;i<=pageNum;i++){
            pageBean p = new pageBean();
            p.setPageNum(i);
            numbers.add(p);

        }
        //给前端页面传入参数
        request.setAttribute("numbers",numbers);
       String  page = request.getParameter("pageNum");
        int pageCurNum = 1;
        if(page!=null){
            pageCurNum = Integer.valueOf(page);
        }
        List<School> list=schoolMapper.getInfo((pageCurNum-1)*15,15);
        request.setAttribute("list",list);
        return "my";
    }

}
